<template>
    <div class="collect">
        <!-- 收藏页面 -->
        <div v-if="collect.length > 0">
            <div v-for="(item, index) in collect" :key="item.store_name + index" class="collect-item">
                <router-link tag="img" :src="item.image" alt="" :to="`/details/${item.pid}`" />
                <div class="left">
                    <h2>{{ item.store_name }}</h2>
                    <div>
                        <span>￥{{ item.price }}</span>
                        <i @click.stop="del(item.pid)">删除</i>
                    </div>
                </div>
            </div>
        </div>

        <!-- 没有数据,显示推荐 -->
        <div v-else class="recom">
            <img src="../../assets/image/noGood.png" alt="" />
            <recom-mended></recom-mended>
        </div>
    </div>
</template>

<script>
import RecomMended from "../RecomMended.vue";
export default {
    components: { RecomMended },
    data() {
        return {
            collect: [],
        };
    },
    methods: {
        getCollect() {
            this.axios.get("/collect/user?page=1&limit=20").then((re) => {
                console.log(re);
                this.collect = re;
            });
        },
        del(id) {
            this.axios.post("/collect/del", { category: "product", id: id }).then((re) => {
                if (re.status == 200) {
                    this.$toast("删除成功");
                    this.getCollect();
                }
            });
        },
    },
    created() {
        this.getCollect();
    },
};
</script>

<style lang="scss" scoped>
.collect {
    background: #f5f5f5 !important;
    height: 100vh;
}
.collect-item {
    display: flex;
    justify-content: space-around;
    height: 90px;
    align-items: center;

    background: rgb(255, 255, 255) !important;
    img {
        width: 65px;
        height: 65px;
    }
    .left {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        // border: 1px solid red;
        height: 65px;
        h2 {
            width: 267.5px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            font-size: 14px;
        }
        div {
            display: flex;
            justify-content: space-between;
            span {
                font-size: 14px;
                color: red;
                margin-top: 10px;
            }
            i {
                font-size: 12px;
                border: 1px solid rgba(87, 84, 84, 0.6);
                padding: 3px 10px;
                line-height: 16px;
            }
        }
    }
}
// 没有数据的样式
.recom {
    img {
        width: 207px;
        height: 168px;
        margin: 0 auto;
    }
}
</style>
